﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace TSVNAddinUtils
{
	public class RegistryAdapter
	{
		public virtual string GetValue(string keyName, string valueName)
		{
			using (RegistryKey subKey = Registry.LocalMachine.OpenSubKey(keyName, false))
			{
				if (subKey == null)
					return string.Empty;

				return (string)subKey.GetValue(valueName, string.Empty);
			}
		}

		public virtual void SetValue(string keyName, string valueName, object value)
		{
			using (RegistryKey subKey = Registry.LocalMachine.CreateSubKey(keyName))
			{
				subKey.SetValue(valueName, string.Empty);
			}
		}

		public virtual bool ExistsKey(string keyName)
		{
			using (RegistryKey subKey = Registry.LocalMachine.OpenSubKey(keyName, false))
			{
				if (subKey == null)
					return false;

				return true;
			}
		}

		public virtual void DeleteValue(string keyName, string valueName)
		{
			using (RegistryKey subKey = Registry.LocalMachine.OpenSubKey(keyName, true))
			{
				if (subKey == null)
					return;

				subKey.DeleteValue(valueName);
			}
		}
	}
}
